import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'

export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src')
    }
  },
  optimizeDeps: {
    include: [
      'tinymce/tinymce',
      'tinymce/models/dom',
      'tinymce/themes/silver',
      'tinymce/icons/default'
    ]
  },
  build: {
    lib: {
      entry: './src/index.js',
      name: 'VueTinymceEditor',
      fileName: (format) => `vue-tinymce-editor.${format}.js`
    },
    rollupOptions: {
      // ⚠️ 决定是否 external tinymce
      external: ['vue', '@tinymce/tinymce-vue', 'tinymce'],
      output: {
        globals: {
          vue: 'Vue',
          '@tinymce/tinymce-vue': 'TinymceVue',
          tinymce: 'tinymce'
        }
      }
    }
  }
})
